from radarssd_sql import *

#数据集路径
file_path_list = ["/home/gary/Code/dataset/radar/cons10M.txt",
                  "/home/gary/Code/dataset/radar/sliding10M.txt",
                  "/home/gary/Code/dataset/radar/ds10M.txt",
                  "/home/gary/Code/dataset/radar/wobu10M.txt"]

# file_path_list = ["/home/gary/Code/dataset/radar/cons10K.txt",
#                   "/home/gary/Code/dataset/radar/sliding10K.txt",
#                   "/home/gary/Code/dataset/radar/ds10K.txt",
#                   "/home/gary/Code/dataset/radar/wobu10K.txt"]

if __name__ == "__main__":
    conn = connect_db()
    cursor = conn.cursor()

    #先清空数据库
    cursor.execute(build_cleardb_query())
    conn.commit()

    line_count = 0
    if_continue = 999
    for file_name in file_path_list:
        with open(file_name,"r") as fd:
            for line in fd:
                toa = int(line)
                try:
                    cursor.execute(build_insert_query(toa,toa+1,toa+2))

                    line_count += 1
                    if(line_count % 2048 == 0):
                        conn.commit()
                        print("inserted %d lines"%line_count)

                except:
                    if(if_continue == 999): #后面的所有错误都忽略
                        continue
                    try:
                        if_continue = eval(input("Error when insert TOA %d"%toa))
                        if(if_continue == 999): 
                            continue
                    except:
                        pass